var app = getApp(),
  common = require("../common/common.js");

Page({
  data: {
    footerCurr: 2
  },
  // 选择科目展示
  checkedModule(res) {
    console.log(res.currentTarget.dataset.ind)
    let _t = this
    _t.setData({
      moduleCheck: res.currentTarget.dataset.ind
    })
  },

  //选择试卷考试  
  selectpaper(t){
    let id = t.currentTarget.dataset.id
    //判断当前用户是否已经考试

    app.util.request({
      url: 'entry/wxapp/AlreadyTested',
      data: {
        id: id
      },
      success: function (a) {
        console.log(a, '试卷')
        console.log(a.data.code, 'code')
        if (a.data.code == 1){
          wx.showModal({
            title: '温馨提示',
            content: a.data.msg,
            success(res) {
              if (res.confirm) {
                console.log('用户点击确定')
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        }else{
          wx.navigateTo({
            url: '/xc_train/pages/online/start/start?id=' + id
          })
        }
      }
    })



  },



  // 选择模拟考试科目
  chooseSubject(t) {
    let _t = this
    let moduleName = t.currentTarget.dataset.name
    let id = t.currentTarget.dataset.id
    let type = t.currentTarget.dataset.type
    let category_id = t.currentTarget.dataset.category_id
    wx.navigateTo({
      url: '/xc_train/pages/online/start/start?name=' + moduleName + '&id=' + id + '&type=' + type + '&category_id=' + category_id   
    })
  },
  //查询时间  
  testPaper(t){
    app.util.request({
      url: 'entry/wxapp/TestPaper',
      data: {},
      success: function (a) {
        console.log(a,'试卷')
        t.setData({
          module: a.data.data
        })
      }
    })
  },

  // 科目列表
  subjects(t) {
    app.util.request({
      url: 'entry/wxapp/SelectAllType',
      data: {},
      success: function(a) {
        console.log(a)
        t.setData({
          module: a.data.data
        })
      }
    })
  },
  onLoad: function(options) {
    console.log(app.userinfo,'用户信息')
    let that = this
    //验证当前用户身份
    let _user = app.userinfo;
    if ((_user.identity == 1 || _user.identity == 2 || _user.identity == 0) && _user.is_auth == 0){
      wx.showModal({
        title: '会员专区',
        confirmText: '去注册',
        content: '您是游客暂无查阅权限',
        success(res) {
          if (res.confirm) {
            console.log('用户点击确定')
            wx.navigateTo({
              url: "/xc_train/pages/theLogin/registered/registered?type=0"
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }

    common.config(that), common.theme(that)
    //that.subjects(that)
    that.testPaper(that)

  },

  onReady: function() {

  },
  onShow: function() {

  },
  onHide: function() {

  },
  onUnload: function() {

  },
  onPullDownRefresh: function() {

  },
  onReachBottom: function() {

  },
  onShareAppMessage: function() {

  }
})